package com.tudouji.project.product.service.impl;

import java.util.List;

import com.tudouji.common.utils.DateUtils;
import com.tudouji.common.utils.IdUtils;
import com.tudouji.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.product.mapper.CategoryMapper;
import com.tudouji.project.product.domain.Category;
import com.tudouji.project.product.service.ICategoryService;

/**
 * 分类Service业务层处理
 * 
 * @author tudouji
 * @date 2020-12-28
 */
@Service
public class CategoryServiceImpl implements ICategoryService 
{
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Category selectCategoryById(Long id) {
        return categoryMapper.selectCategoryById(id);
    }

    /**
     * 查询分类
     * 
     * @param guid 分类ID
     * @return 分类
     */
    @Override
    public Category selectCategoryByGuid(String guid)
    {
        return categoryMapper.selectCategoryByGuid(guid);
    }

    /**
     * 查询分类列表
     * 
     * @param category 分类
     * @return 分类
     */
    @Override
    public List<Category> selectCategoryList(Category category)
    {
        return categoryMapper.selectCategoryList(category);
    }

    /**
     * 新增分类
     * 
     * @param category 分类
     * @return 结果
     */
    @Override
    public int insertCategory(Category category)
    {
        category.setGuid(IdUtils.fastSimpleUUID());
        category.setCreatetime(DateUtils.getNowDate());
        category.setOperatorid(SecurityUtils.getLoginUser().getUser().getUserId().toString());
        category.setOperator(SecurityUtils.getUsername());
        return categoryMapper.insertCategory(category);
    }

    /**
     * 修改分类
     * 
     * @param category 分类
     * @return 结果
     */
    @Override
    public int updateCategory(Category category)
    {
        return categoryMapper.updateCategory(category);
    }

    /**
     * 批量删除分类
     * 
     * @param guids 需要删除的分类ID
     * @return 结果
     */
    @Override
    public int deleteCategoryByIds(String[] guids)
    {
        return categoryMapper.deleteCategoryByIds(guids);
    }

    /**
     * 删除分类信息
     * 
     * @return 结果
     */
    @Override
    public int deleteCategoryById(Long id)
    {
        return categoryMapper.deleteCategoryById(id);
    }
}
